package cn.edu.scau.dormitory_management_system.service.impl;

import cn.edu.scau.dormitory_management_system.dao.BillDao;
import cn.edu.scau.dormitory_management_system.entity.BillEntity;
import cn.edu.scau.dormitory_management_system.entity.DormbuildEntity;
import cn.edu.scau.dormitory_management_system.service.BillService;
import cn.hutool.core.date.DateTime;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;



@Service("billService")
public class BillServiceImpl extends ServiceImpl<BillDao, BillEntity> implements BillService {


    @Override
    public boolean delete(BillEntity billEntity){
        return this.baseMapper.deleteById(billEntity) > 0;
    }

    @Override
    public boolean create(BillEntity billEntity){
        billEntity.setBillTime(DateTime.now());
        billEntity.setSurplus(billEntity.getEnergy()+billEntity.getWater());
        System.out.println(billEntity);
        return this.baseMapper.insert(billEntity) > 0;
    }

    @Override
    public boolean update(BillEntity billEntity) {
        billEntity.setSurplus(billEntity.getEnergy()+billEntity.getWater());
        billEntity.setBillTime(DateTime.now());
        return  this.baseMapper.updateById(billEntity) > 0;
    }

    @Override
    public List<BillEntity> findByDormName(String dormName){
        List<BillEntity> billEntities = this.baseMapper.selectList(new QueryWrapper<BillEntity>().eq("dorm_name", dormName));
        return billEntities;
    }

    @Override
    public List<BillEntity> findByDormBuildId(int dormBuildId){
        List<BillEntity> billEntities = this.baseMapper.selectList(new QueryWrapper<BillEntity>().eq("dorm_build_id", dormBuildId));
        return billEntities;
    }

}